﻿@using SQLiteCoreDB.Models;
@{
    ViewBag.Title = "文件列表";
    var list = ViewBag.listMy as List<FileInfoMy>;

}
<style>
    tr:hover {
        background: #cccccc;
    }
</style>
<div style="margin-bottom:100px;">

    @if (LoginMode.LV != "1" || LoginMode.admin)
    {

        <table class="layui-table" lay-skin="line">
            <thead>
                <tr>
                    <th>时间</th>
                    <th>大小</th>
                    <th>文件 </th>
                    @if (LoginMode.admin)
                    {
                        <th>操作</th>
                    }

                </tr>
            </thead>
            <tbody id="list_box">
                @Html.Partial("../Home/ModeList")
            </tbody>
        </table>

        <div style="display:none; " id="win_mkdir">
            <div style=" padding:30px;">
                <div style="font-size:12px;margin-bottom:30px;">文件夹名称，（对于英文符号）不允许包含\ / : * ? “ < > |</div>
                <div>
                    <input type="text" id="txtFolder" placeholder="文件夹名称" class="layui-input" oninput="checkVal(this);" />
                </div>
                <div style="margin-top:30px;text-align:center;">
                    <input type="button" value="确定" class="layui-btn layui-btn-lg layui-btn-normal" onclick="doMkdir(this)" />
                </div>
            </div>
        </div>




    }
    else
    {
        <h1 style="width: 320px; position: absolute; top: 28%; bottom: 0; left: 0; right: 0; margin: auto; ">
            无权查看！等待审核
        </h1>
    }
</div>


<script type="text/javascript">

    const delFile = (file, Dir) => {
        // 发送删除文件的请求
        axios.get('/Home/DelFile', {
            params: {
                file: file
            }
        }).then(response => {

            const result = response.data; // 请求成功，处理返回的结果
            if (result.Code === 200) {

                GetFileList(Dir); // 删除成功
                layer.msg(result.Msg);

            } else {
                layer.msg(result.Msg);
            }
        }).catch(error => {

            layer.msg(result.Msg); // 请求发生错误
        });
    };
    async function GetFileList(dirNew) {
        let response = null;

        if (dirNew === null || dirNew === "") {
            response = await axios.post('/Home/GetFileList');
        } else {
            response = await axios.get('/Home/SeeDir', {
                params: {
                    dirNew: dirNew,
                    Dir: 1
                }
            })
        }

        if (response != null) {
            $("#list_box").html(response.data);
        }

    };
    layui.use(function () {
        var layer = layui.layer;
        var util = layui.util;
        // 批量事件
        util.on('lay-on', {
            page: function () {
                // 页面层
                layer.open({
                    type: 1,
                    shadeClose: true,
                    area: ['480px', '280px'], // 宽高
                    title: "创建文件夹", // 不显示标题栏
                    content: $("#win_mkdir").html(),
                });
            },
            iframe: function () {
                // iframe 层
                layer.open({
                    type: 2,
                    title: '上传文件',
                    shadeClose: false,
                    shade: 0.8,
                    area: ['60%', '70%'],
                    content: '/File/upload?dir=@ViewBag.dirNew' // iframe 的 url

                });
            },

        });
    });

    function checkVal(s) {
        var value = s.value;
        console.log(value);
        value = value.replace("\\", "");
        value = value.replace("/", "");
        value = value.replace(":", "");
        value = value.replace("*", "");
        value = value.replace("?", "");
        value = value.replace("\"", "");
        value = value.replace("<", "");
        value = value.replace(">", "");
        value = value.replace("|", "");
        s.value = value;
    }
    function doMkdir(button) {
        var name = $(".layui-layer-content").find("#txtFolder").val().myTrim();
        if (name == "") {
            layui.layer.msg("文件夹名称不可为空");
            return;
        }
        $(button).attr("disabled", "disabled");
        $.ajax({
            url: "@Url.Action("MkdirFolder", "file")",
            type: "post",
            data: {
                folder: name,
                dir: "@Html.Raw(ViewBag.dirNew)"
            },
            success: function (r) {
                if (r.Code == 500) {
                    $(button).removeAttr("disabled");
                    layui.layer.alert("出错：" + r.Msg);
                } else {

                    layui.layer.msg(r.Msg);
                    if (r.Code == 200) {
                        GetFileList("@Html.Raw(ViewBag.dirNew)");
                    }
                }
            }
        });
    }
</script>